/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.action;

import east2west.dao.HotelDAO;
import east2west.dto.HotelDTO;
import east2west.service.HotelService;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author thanhluan
 */
public class HotelAction extends DispatchAction {

    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    HotelService hotelSer = null;

  
    public ActionForward hotelDetail(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        hotelSer = new HotelService();
        int id = Integer.parseInt(request.getParameter("id"));
        HotelDAO dao = new HotelDAO();
        HotelDTO hotelDTO = dao.findById(id);
        //-----------------------------------------------------------
        //Hotel Orther
        ArrayList<HotelDTO> listOrtherHotel = dao.findByAllOrther(id);
        request.setAttribute("listOrtherhotel",listOrtherHotel);
        request.setAttribute("hotelDTO", hotelDTO);
        request.setAttribute("page","hoteldetail.page");
        return mapping.findForward(SUCCESS);
    }

   
    public ActionForward listHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<HotelDTO> listHotel = new ArrayList<HotelDTO>();
        hotelSer = new HotelService();
        listHotel = hotelSer.readByAll();
        request.setAttribute("listHotel",listHotel);
        request.setAttribute("page","hotellist.page");

        return mapping.findForward(SUCCESS);
    }
      public ActionForward searchHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
          hotelSer = new HotelService();
      String city = request.getParameter("city");
      HotelDTO dto = new HotelDTO();
      dto.setCity(city);
      ArrayList<HotelDTO> listSearch = hotelSer.findDTO(dto);
      request.setAttribute("listSearch", listSearch);
      request.setAttribute("page", "hotellists.page");

        return mapping.findForward(SUCCESS);
    }
}
